<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>解析二维码</title>
        <style>
            #qrcode {
                width: 160px;
                height: 160px;
                margin-top: 15px;
            }

            #text {
                height: 23px;
            }

            #button {
                height: 29px;
            }

            #img {
                width: 200px;
                height: 200px;
            }
        </style>
    </head>

    <body>
        <div style="width:360px;height:360px;">
            <h2 style="margin-left: 30px;">解析二维码</h2>
            <input type="file" id="newfile"></br>
            <img id="img" />
            <h4>二维码地址:<span id="spantitle"></span></h4>
        </div>
        <h2><a href="index.html">我要生成二维码</a></h2>
    </body>
</html>
<script src="js/jquery.min.js"></script>
<script src="js/reqrcode.js"></script>
<script type="text/javascript">
    // 解析
    var newfile = document.getElementById('newfile');

    var getObjectURL = function (file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }


    newfile.onchange = function () {
        // 显示图片
        var reads = new FileReader();
        f = document.getElementById('newfile').files[0];
        reads.readAsDataURL(f);
        reads.onload = function (e) {
            document.getElementById('img').src = this.result;
            $("#img").css("display", "block");
        };
        //   console.log(newfile[0]);
        console.log(getObjectURL(this.files[0]));// newfile[0]是通过input file上传的二维码图片文件
        qrcode.decode(getObjectURL(this.files[0]));
        qrcode.callback = function (imgMsg) {
            // 获取地址传给span
            var divA = document.getElementById("spantitle");
            divA.innerHTML = divA.innerHTML + imgMsg;
        }
    }
</script>